<template>
  <div>
    <van-nav-bar
      fixed
      placeholder
      safe-area-inset-top
      title="我的钱包"
      @click-left="back"
    >
      <template #left>
        <van-icon name="arrow-left" size="16px" color="#333" />
      </template>
    </van-nav-bar>
    <div class="moenycard">
      <div class="showword">
        <div>钱包余额（元）</div>
        <div class="moeny">{{ withdrawAmount }}</div>
      </div>
      <div>
        <van-button plain type="info" @click="jump">提现</van-button>
      </div>
    </div>
    <div class="detail">
      <div class="tip">钱包明细</div>
      <div
        v-for="(item, index) in drawlist"
        v-show="drawlist.length != 0"
        :key="index"
        class="part"
      >
        <div style="margin-bottom: 10px">
          <span class="word1">提现时间：</span>
          <span class="word2">{{ item.create_time }}</span>
          <span class="delmoeny">{{ item.aomunt }}</span>
        </div>
        <div v-if="item.house_sn">
          <span class="word3"
            >房源编号：<span>{{ item.house_sn }}</span
            ><span class="copy" @click="copy(item.house_sn)">复制</span></span
          >
          <span class="retmoeny"
            >余额：￥<span>{{ item.current_amount }}</span></span
          >
        </div>
        <div class="status">
          <span>{{ item.describe }}：</span>
          <span>{{ item.status }}</span>
        </div>
      </div>
      <div v-show="!drawlist">暂无流水帐记录</div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { amountLog } from "@/apis/user";
export default {
  data() {
    return {
      drawlist: [],
    };
  },
  computed: {
    ...mapGetters(["withdrawAmount", "role", "agent"]),
  },
  created() {
    this.runningRecords();
  },
  methods: {
    runningRecords() {
      amountLog().then((res) => {
        console.log("amountLog", res);
        if (res.code == 200 || res.code == 201) {
          this.drawlist = res.result.list;
        }
      });
    },
    copy(e) {
      this.$copyText(e).then(() => {
        this.$toast.success("复制成功");
      });
    },
    back() {
      this.$router.go(-1);
    },
    jump() {
      if (this.withdrawAmount == 0) {
        this.$toast("您当前可提现金额为0");
      } else if (this.role == 2) {
        this.$router.push({ path: "/withdraw" });
      } else if (this.role == 4 && this.agent.vip == 2) {
        this.$router.push({ path: "/WithDrawAgent" });
      } else if (this.role == 4 && this.agent.vip == 1) {
        this.$dialog
          .confirm({
            title: "温馨提示",
            className: "leftpart",
            confirmButtonText: "立即购买",
            confirmButtonColor: "#45b7cb",
            cancelButtonText: "取消",
            message: "提现功能需要缴纳会员才能使用，是否购买？",
            messageAlign: "left",
          })
          .then(() => {
            this.$router.push({ path: "/buyjoin" });
          })
          .catch(() => {});
      }
    },
  },
};
</script>

<style lang="less" scoped>
.moenycard {
  margin: 0 10px;
  padding-top: 30px;
  box-sizing: border-box;
  height: 110px;
  box-shadow: 0 8px 5px #a3dce7;
  background-image: linear-gradient(to bottom right, #6fccdd, #49b9cd);
  display: flex;
  justify-content: space-around;
  border-radius: 10px;
  .showword {
    color: #fff;
    font-size: 14px;
    .moeny {
      font-size: 30px;
    }
  }
  .van-button {
    margin-left: 40px;
    width: 80px;
    height: 35px;
    border: none;
    border-radius: 20px;
    color: #45b7cb;
    background-color: #f1f1f1;
  }
}
.detail {
  margin: 40px 10px 0;
  padding-bottom: 15px;
  .tip {
    margin-bottom: 20px;
    font-size: 17px;
    font-weight: bold;
  }
  .part {
    padding-top: 10px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ccc;
    .status {
      margin-top: 10px;
      & > span:first-child,
      & > span:last-child {
        font-size: 14px;
      }
      & > span:last-child {
        font-weight: bold;
        color: #45b7cb;
      }
    }
    .delmoeny {
      font-size: 16px;
      float: right;
      color: #d43b33;
      font-weight: bold;
    }
    .retmoeny {
      float: right;
      font-size: 13px;
      margin-bottom: 10px;
      font-weight: bold;
      line-height: 18.39px;
    }
    .word1,
    .word2 {
      font-size: 14px;
    }
    .word3 {
      font-size: 14px;
    }
    .copy {
      color: #d43b33;
      margin-left: 5px;
      font-size: 13px;
      font-weight: bold;
    }
  }
}
</style>
